/*子应用*/
const express = require("express")

const query = require("../pool")

const home = express.Router()

// 轮播图
home.get("/swipe", async (req, res) => {
  let result = await query(`select img from home_rec where type='swipe';`)
  // console.log(result)
  if (result.length == 0) {
    res.send({ code: 0, msg: "未查询到相关结果" })
  } else {
    res.send({ code: 1, msg: "搜索成功", data: result })
  }
})

// 首单全额返
home.get("/yuan", async (req, res) => {
  let result = await query(
    `select cake_pic,cake_price,cid,cakename from cakelist  where discount_type=2 limit 3;`
  )
  // console.log(result)
  if (result.length == 0) {
    res.send({ code: 0, msg: "未查询到相关结果" })
  } else {
    res.send({ code: 1, msg: "搜索成功", data: result })
  }
})

// 获取推荐商品数据
home.get("/all", async (req, res) => {
  // let obj = req.query
  // console.log(obj)
  let result = await query(
    `select home_rec.img,cakelist.cakename,cakelist.cake_description,cakelist.cid,cakelist.cakename from home_rec,cakelist where home_rec.idid=cakelist.cid;`
  )
  // console.log(result)
  if (result.length == 0) {
    res.send({ code: 0, msg: "未查询到相关结果" })
  } else {
    res.send({ code: 1, msg: "搜索成功", data: result })
  }
})

//暴露
module.exports = home
